package com.xpchenfrank.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.xpchenfrank.service.BlogService;
import com.xpchenfrank.service.StockService;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.springframework.stereotype.Component;

import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author xpchen
 * @time 2018/3/8 20:03
 * @Description
 * @copyright Wuxi Yazuo ,Ltd.copyright 2015-2025
 */
@Component
public class BlogServiceImpl implements BlogService {

    @Override
    public String getCSDNBlog() {

        WebDriver driver = new HtmlUnitDriver();

        // And now use this to visit Google
        driver.get("https://blog.csdn.net/wangpeng047");

        //driver.findElement(By.cssSelector("#food span.dairy.aged"));

        //查招考简章与公告的信息
        WebElement foundEle = driver.findElement(By.xpath("//*[@id=\"mainBox\"]/main/div[2]/div[1]/h4/a"));

        String jianzhang = foundEle.getText();

        System.out.println("内容是 " + jianzhang);

        System.out.println("试试吧");

        return jianzhang;

    }
}
